/**
 * DVN: Distributed Virtual Network Simulation Platform
 * Copyright (c) 2006-2009 Tyson Malchow <tyson.malchow@gmail.com>
 *
 * This file is part of the DVN distributed virtual network simulation
 * program.
 *
 * DVN is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DVN is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DVN.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _simop_h
#define _simop_h

#include <netinet/in.h>

#include "evtracker.h"
#include "nbdf.h"

#define SIMOP_CODE_CNODES        1
#define SIMOP_CODE_NETWORK       2
#define SIMOP_CODE_END           3
#define SIMOP_CODE_MODLOAD       4

#define SIMOP_CNODES_BOOTSTRAP   1
#define SIMOP_CNODES_TRACKING    2

#define SIMOP_NETWORK_CREATE     1
#define SIMOP_NETWORK_DISCONNECT 2
#define SIMOP_NETWORK_CONNECT    3

#define SIMOP_CNODES_CLARGS_LEN 512

typedef struct simop_t {
	int opcode;
	ptime_t target_time;

	union {
		struct {
			unsigned int quantity;

			unsigned int network_id;
			unsigned int module_id;

			unsigned int logging_level;
			unsigned char logging_channel;

			char flags;

			unsigned int tracker_id;
			unsigned int bootstrap_id;

			char cl_args[SIMOP_CNODES_CLARGS_LEN];
		}cnodes;

		struct {
			unsigned int id;
			char file[200];
			unsigned int argc;
			char ** argv;
		} modload;

		struct {
			 unsigned int id1, id2;
			 unsigned int base_delay, width, tail_width, reliability;
			 unsigned char method;
		} network;
	} detail;
} simop_t, * simop_tp;


typedef evtracker_tp simop_list_tp;
#define simop_earliest_event evtracker_earliest_event

simop_list_tp simop_list_create (void) ;
void simop_list_destroy( simop_list_tp list );
void simop_list_add( simop_list_tp list, simop_tp op, ptime_t time);
int simop_list_size( simop_list_tp list );
simop_tp simop_get_next( simop_list_tp list, ptime_t * time );
simop_tp simop_look_next( simop_list_tp list, ptime_t * time);

/* network encoding/decoding */
simop_tp simop_nbdf_decode(nbdf_tp nb);
nbdf_tp simop_nbdf_encode(simop_tp sop);


#endif

